package cloud.lysky.java.on.reflect;

import java.util.Random;

/**
 * @author luoly
 * @describe
 * @date 2022-09-22 13:59
 **/
public class ClassInitialization{
    public static Random rand = new Random(47);

    public static void main(String[] args) throws ClassNotFoundException {
        Class initable = Initable.class;
        System.out.println("创建Initable后");
        //不会触发初始化
        System.out.println(Initable.STATIC_FINAL);
        //触发初始化
        System.out.println(Initable.STATIC_FINAL_2);
        //触发初始化
        System.out.println(Initable2.staticNonFinal);
        Class<?> aClass = Class.forName("cloud.lysky.java.on.reflect.Initable3");
        System.out.println("创建Initable3后");
        System.out.println(Initable3.staticNonFinal);
    }
}

class Initable {
    static final int STATIC_FINAL = 47;
    static final int STATIC_FINAL_2 = ClassInitialization.rand.nextInt(1000);
    static{
        System.out.println("Initable 初始化");
    }
}

class Initable2{
    static int staticNonFinal = 147;
    static {
        System.out.println(" Initable2 初始化");
    }
}

class Initable3{
    static int staticNonFinal = 74;
    static {
        System.out.println(" Initable3 初始化");
    }
}